<?php

class DiscountController extends BaseController
{
	
	/**
	 * 限时折扣管理
	 */
	public function actionAdmin()
	{
		$model=new CmpPromotion('search');
		$model->unsetAttributes();  // clear any default values
		$model->zcr_type = 5;//类型： 1减金额  2赠送优惠券 3赠送赠品 4免运费 5 限时折扣活动
		if(isset($_GET['CmpPromotion']))
			$model->attributes=$_GET['CmpPromotion'];
		
		$this->render('admin',array(
				'model'=>$model,
		));
	}
	
	/**
	 * 单条批量删除限时折扣
	 */
	public function actionDelete(){
		//操作ID号格式处理
		if(isset($_GET['id'])){
			$id = $_GET['id'];
		}elseif(isset($_POST['ids'])){
			$id =$_POST['ids'];
		}else{
			throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
		}
		$id = is_array($id)?join(',',$id):(int)$id;
		//处理条件
		$criteria=new CDbCriteria;
		$criteria->addCondition("zcr_id in ($id)");
		//修改内容
		$set = array('zcr_status'=>'3');
		//执行操作:商家活动设为删除
		if(CmpPromotion::model()->updateAll($set,$criteria)){
			//限时折扣产品设为删除
			$set = array('zpd_status'=>'3');
			if(ProDiscount::model()->updateAll($set,$criteria)){
				//成功跳转
				$this->redirect(Yii::app()->request->urlReferrer);
			}
		}else{
			//失败跳转
			$this->render('../index/error',array('message'=>'对不起，删除操作失败，请稍后再试！'));
			exit;
		}
	}


}